package com.oceansoft.mobile.econsole.modules.api.controller;

import com.oceansoft.mobile.econsole.modules.base.entity.ApiPager;
import com.oceansoft.mobile.econsole.modules.base.entity.Query;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.mappoint.service.IMapPointService;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * Class: ApiMapPointController
 * Title: 地图服务
 * Desc: 根据手机自动定位，市民在百度地图上
 * 查看附近2公里内的公安局、派出所、公交站等坐标信息
 * <p>
 * Created： wzy
 * Date： 2016/2/17
 */
@RestController
@RequestMapping("api/map")
public class ApiMapPointController {

    @Resource
    private IMapPointService mapPointService;

    /**
     * 坐标转换，
     * 百度坐标与地图坐标的转换
     * @param request
     * @return
     */
    @RequestMapping(value = "coord/trans", method = GET)
    public Result coordinateTransformation(HttpServletRequest request) {

        return mapPointService.coordinateTransformation();
    }

    /**
     * 获取地图服务接口
     * @param query
     * @return
     */
    @RequestMapping(value = "interest", method = POST)
    public Result getMapInterest(@RequestBody Query query) {

        if (StringUtils.isBlank(query.getLongitude()) || StringUtils.isBlank(query.getLatitude())) {
            return new Result(Result.FAILURE, "经纬度为空");
        }

        Result result = new Result();

        ApiPager returnPage = mapPointService.getMapInterest(query);
        result.setSucc(Result.SUCC);
        result.setData(returnPage);
        result.setMsg("查找附近公安机关成功");
        return result;
    }

}
